package com.sls.game.dao.maxshu.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.impl.SuperDAO;
import com.sls.game.dao.maxshu.MaxshuDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.maxshu.MaxshuProduct;

@Repository("maxshuDAO")
public class MaxshuDAOImpl extends SuperDAO<MaxshuProduct> implements
		MaxshuDAO {

	@Override
	public void insertProduct(MaxshuProduct product) {
		this.getSqlSession().insert("mybatis.xml.MaxshuProductMapper.insert",
				product);

	}

	@Override
	public void update(MaxshuProduct product) {
		this.getSqlSession().update("mybatis.xml.MaxshuProductMapper.update",
				product);

	}

	@Override
	public MaxshuProduct queryById(String id) {
		return this.getSqlSession().selectOne(
				"mybatis.xml.MaxshuProductMapper.selectByPrimaryKey", id);
	}

	@Override
	public Pagination<MaxshuProduct> queryPage(MaxshuProduct product) {
		Pagination<MaxshuProduct> paginationList = null;
		Integer rowCount = queryRowCount(product);

		product.calculate();
		List<MaxshuProduct> list = queryGoodsInfoList(product);
		paginationList = this.queryPagination(rowCount, list, product);
		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private Integer queryRowCount(MaxshuProduct product) {
		Integer rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.MaxshuProductMapper.queryRowCount", product);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private List<MaxshuProduct> queryGoodsInfoList(MaxshuProduct product) {
		List<MaxshuProduct> list = this.getSqlSession().selectList(
				"mybatis.xml.MaxshuProductMapper.queryMaxshuProductInfoList",
				product);
		return list;
	}

	@Override
	public MaxshuProduct queryByProId(String proId) {
		return this.getSqlSession().selectOne(
				"mybatis.xml.MaxshuProductMapper.queryByProId", proId);
	}

	@Override
	public List<MaxshuProduct> queryAllWoInfo(MaxshuProduct product) {
		List<MaxshuProduct> list = this.getSqlSession().selectList(
				"mybatis.xml.MaxshuProductMapper.queryAllWoInfo", product);
		return list;
	}

}
